package dbLayer;

import java.util.List;

import modelLayer.Block;
import modelLayer.TeachingBlock;

public interface DBBlockIF {
	
	/**
	 * Inserts n new rows into the database table Block, where n
	 * is numberOfBlocks. This method uses prepared statements to 
	 * sanitize our database input.
	 * 
	 * @param	schId			int				the id of the schedule to add the
	 * 											blocks to.
	 * @param	numberOfBlocks	int				number of blocks to add.
	 * @return	rc				int				count of rows affected by the query execution in the database
	 */
	public int insert(int schId, int numberOfBlocks);
	
	/**
	 * Finds a row in the database table Block.
	 * 
	 * @param	schId				int				the id of the schedule to find
	 * 												the block in.
	 * @param	blockNumber			int				number of the block.
	 * @param	retrieveAssociation	boolean			determines if we're to retrieve 
	 * 												associations or not.
	 * @throws	Exception							throws SQL exceptions if the query isn't
	 * 												legal.
	 * @return						Block			returns the block matching the search.
	 */
	public Block find(int schId, int blockNumber, boolean retriveAssociation) throws Exception;
	
	/**
	 * Finds a row in the database table Block.
	 * 
	 * @param	id					int				id of the block.
	 * @param	retrieveAssociation	boolean			determines if we're to retrieve 
	 * 												associations or not.
	 * @throws	Exception							throws SQL exceptions if the query isn't
	 * 												legal.
	 * @return						Block			returns the block matching the search.
	 */	
	public Block findById(int id, boolean retriveAssociation) throws Exception;
	
	/**
	 * Finds a set of rows in the database table Block.
	 * 
	 * @param	blockNumber			int				the number of the blocks to be found.
	 * @param	retrieveAssociation	boolean			determines if we're to retrieve 
	 * 												associations or not.
	 * @throws	Exception							throws SQL exceptions if the query isn't
	 * 												legal.
	 * @return						List<Block>		returns the blocks matching the search.
	 */	
	public List<Block> findBlocksByNumber(int blockNumber, boolean retriveAssociation) throws Exception;
	
	/**
	 * Finds all rows in the database table Block. 
	 * 
	 * @param	retrieveAssociation	boolean	determines if we're to retrieve 
	 * 										associations or not.
	 * @throws	Exception					throws SQL exceptions if the query isn't
	 * 										legal.
	 * @return				List<Block>		returns a list of blocks.
	 */	
	public List<Block> getAll(boolean retriveAssociation) throws Exception;

	/**
	 * Finds all rows in the database table Block matching the scheduleId. 
	 * 
	 * @param	schId				int				the schedule id in which the blocks
	 * 												are contained.
	 * @param	retrieveAssociation	boolean			determines if we're to retrieve 
	 * 												associations or not.
	 * @throws	Exception							throws SQL exceptions if the query isn't
	 * 												legal.
	 * @return						List<Block>		returns a list of blocks.
	 */	
	public List<Block> getAllBySchedule(int schId, boolean retrieveAssociation) throws Exception;
	
	
	/**
	 * Finds all rows in the database table Block matching the block number where teaching-block is not a null value.
	 * 
	 * @param 	blockNumber				int 			the number of the block
	 * @param 	retrieveAssociation 	boolean			determines if we're to retrieve associations or not.
	 * @return 							List<Block> 	returns a list of blocks.
	 */
	public List<Block> findFilledBlocksByNumber(int blockNumber, boolean retrieveAssociation );
	
	/**
	 * Finds all rows in the database table Block not matching the block number and with the given schedule id.
	 * This method takes the following parameters:
	 * 
	 * @param 	schId					int		the block's schedule id
	 * @param 	retrieveAssociation		boolean	determines if we're to retrieve associations or not.
	 * @param 	blockNumber				int		the block number which the conflict arose in.
	 * @return
	 */
	public List<Block> getAllNonConflictingBySchedule(int schId, boolean retrieveAssociation, int blockNumber);


	/**
	 * Updates data about a block.
	 * 
	 * @param 	schId 			int				the id of the block
	 * @param 	blockNumber		int				the number of the block
	 * @param 	tb				TeachingBlock	an instance of TeachingBlock associated to the block
	 * @return 	rc				int				count of rows affected by the query execution in the database
	 * @throws 	Exception
	 */
	public int update(int schId, int blockNumber, TeachingBlock tb) throws Exception;

	/**
	 * Removes a row in the database table Block. 
	 * 
	 * @param	scheduleId	int			the id of the schedule to find
	 * 									the block in.
	 * @param	blockNumber	int			number of the block.
	 * @throws	Exception				throws SQL exceptions if the query isn't
	 * 									legal.
	 * @return	rc			int			count of rows affected by the query execution in the database
	 */	
	public int remove(int schId, int blockNumber) throws Exception;

	
}
